package com.xu.a2019;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class TotalActivity extends AppCompatActivity {
    private List<String> data;
    private EditText etTotal;
    private EditText etIncr;
    private EditText etDecr;
    private EditText etOther;
private TotalAdapter adapter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_total);
        findViewById(R.id.back_iv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        findViewById(R.id.refresh).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loadData();
            }
        });
        ListView listView = findViewById(R.id.lv);
        etTotal = findViewById(R.id.sy_et);
        etIncr = findViewById(R.id.dt_et);
        etDecr = findViewById(R.id.ds_et);
        etOther = findViewById(R.id.bk_et);
        initData();
        initListView(listView);

    }

    private void loadData() {


    }

    private void initData() {
        data = new ArrayList<>();
        data.add("2019-01,0,0,0");
        data.add("2019-02,0,0,0");
        data.add("2019-03,0,0,0");
        data.add("2019-04,0,0,0");
        data.add("2019-05,0,0,0");
        data.add("2019-06,0,0,0");
        data.add("2019-07,0,0,0");
        data.add("2019-08,0,0,0");
        data.add("2019-09,0,0,0");
        data.add("2019-10,0,0,0");
        data.add("2019-11,0,0,0");
        data.add("2019-12,0,0,0");
        adapter = new TotalAdapter(this,data);
        SharedPreferences sharedPreferences = getSharedPreferences("data", MODE_PRIVATE);
        String total = sharedPreferences.getString("total", "20000");
        String incr = sharedPreferences.getString("incr", "11000");
        String decr = sharedPreferences.getString("decr", "-5000");
        String other = sharedPreferences.getString("other", "-3000");
        etTotal.setText(total);
        etIncr.setText(incr);
        etDecr.setText(decr);
        etOther.setText(other);
    }

    private void initListView(ListView listView) {
        listView.setAdapter(adapter);
        View head = LayoutInflater.from(this).inflate(R.layout.item_total, null);
        TextView tv1 = head.findViewById(R.id.tv_month);
        TextView tv2 = head.findViewById(R.id.tv_shengyu);
        TextView tv3 = head.findViewById(R.id.guding);
        TextView tv4 = head.findViewById(R.id.qita);
        tv1.setText("月份");
        tv2.setText("剩余");
        tv3.setText("固定");
        tv4.setText("花销");
        listView.addHeaderView(head);
    }
}
